package BasicClassUse;

import java.nio.charset.StandardCharsets;

public class StringUse {
    public static void main(String[] args) {
        String a = "java";
        System.out.println("[java]返回指定字符(j)的索引:"+a.indexOf("j"));
        System.out.println("[java]返回指定索引处(0)的字符:"+a.charAt(0));
        System.out.println("[java]字符串替换(j替换J):"+a.replace("j","J"));
        a = " java ";
        System.out.println("[ java ]去除字符串两段空白:"+a.trim());
        a = "java";
        System.out.print("[java]分割字符串,被分割字符(a)返回一个分割后的字符串数组:");
        for (String b:a.split("a")) {
            System.out.print("["+b+"]");
        }
        System.out.println();
        System.out.println("[java]返回字符串的byte类型数组:"+a.getBytes());
        for (byte b:a.getBytes()) {
            System.out.print("["+b+"]");
        }
        System.out.println();
        System.out.println("[java]返回字符串长度:"+a.length());
        System.out.println("[java]将字符串转成小写字母:"+a.toLowerCase());
        System.out.println("[java]将字符串转成大写字母:"+a.toUpperCase());
        System.out.println("[java]截取字符串(从1开始截取值就为ava,0的话还是java):"+a.substring(1));
        a = new String("java");
        String b = new String("java");
        System.out.println("String方法字符串比较(equals一般是引用比较,equals被重写了,本质是==,Integer也是):"+a.equals(b));
    }
}
